package org.wms.minbearwcs.dao.storage.impl;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;
import org.wms.minbearwcs.dao.storage.inf.DualHeadStorageDao;
import org.wms.minbearwcs.entity.Mapper.storage.dualStorage.DualHeadStorageGroupMapper;
import org.wms.minbearwcs.entity.Mapper.storage.dualStorage.DualHeadStorageMapper;
import org.wms.minbearwcs.entity.PO.wcs.storage.dualHeadStorage.DualHeadStorage;

import java.util.List;


@Repository
@RequiredArgsConstructor
public class DualHeadStorageDaoImpl implements DualHeadStorageDao {

    private final DualHeadStorageMapper mapper;

    @Override
    public List<DualHeadStorage> selectByDualHeadStorageGroupCode(String groupCode) {
        return new LambdaQueryChainWrapper<>(mapper)
                .eq(DualHeadStorage::getDualHeadGroupCode,groupCode)
                .list();
    }

    @Override
    public boolean updateBookingPalletById(Integer id, String palletCode) {
        return new LambdaUpdateChainWrapper<>(mapper)
                .eq(DualHeadStorage::getId,id)
                .set(DualHeadStorage::getBookingPalletCode,palletCode)
                .update();
    }

    @Override
    public String selectGroupNameByQrCode(String qrCode) {
        return new LambdaQueryChainWrapper<>(mapper)
                .eq(DualHeadStorage::getQrPoint,qrCode)
                .select(DualHeadStorage::getDualHeadGroupCode)
                .last("LIMIT 1")
                .one()
                .getDualHeadGroupCode();
    }

    @Override
    public boolean updateLockPalletById(Integer id, String palletCode) {
        return new LambdaUpdateChainWrapper<>(mapper)
                .eq(DualHeadStorage::getId,id)
                .set(DualHeadStorage::getLockPallet,palletCode)
                .update();
    }

    @Override
    public boolean updateLockPalletNullByPalletCode(String palletCode) {
        return new LambdaUpdateChainWrapper<>(mapper)
                .eq(DualHeadStorage::getLockPallet,palletCode)
                .set(DualHeadStorage::getLockPallet,null)
                .update();
    }
}
